﻿/**
 * FaderPointer
 *
 * @author		Allen Chou
 * @version		0.1.0 (last update: Jun 7 2008)
 * @link        http://cjcat.blogspot.com
 * @link		http://cjcat2266.deviantart.com
 */

package idv.cjcat.utils.fader {
	import flash.display.*;
	import flash.errors.IllegalOperationError;
	
	import idv.cjcat.*;
	import idv.cjcat.easing.*;
	
	public class FaderPointer {
		
		public var circular:Boolean;
		
		internal var _easingL:Function;
		internal var _easingR:Function;
		
		//internal var _useBand:Boolean = false;
		internal var _position:Number;
		internal var _bandwidthL:Number = 1;
		internal var _bandwidthR:Number = 1;
		
		public function FaderPointer(position:Number = 0, easingL:Function = null, easingR:Function = null, circular:Boolean = true/*, useBand:Boolean = true*/) {
			//this.useBand = useBand;
			this.circular = circular;
			this.position = position;
			
			if (easingL != null) {
				this.easingL = easingL;
			} else {
				this.easingL = Linear.easeOut;
			}
			
			if (easingR != null) {
				this.easingR = easingR;
			} else {
				this.easingR = Linear.easeOut;
			}
		}
		
		//public methods
		//------------------------------------------------------------------------------------------------
		
		public function clone():FaderPointer {
			var temp:FaderPointer = new FaderPointer();
			temp.circular = circular;
			temp.easingL = _easingL;
			temp.easingR = _easingR;
			temp.position = _position;
			//temp.useBand = _useBand;
			temp.bandwidthL = _bandwidthL;
			temp.bandwidthR = _bandwidthR;
			return temp;
		}
		
		//end of public methods
		//------------------------------------------------------------------------------------------------
		
		
		//private methods
		//------------------------------------------------------------------------------------------------
		
		/*
		private function setUpdate():void {
			if (_useBand) {
				//update = Fader.update_useBand_circular;
				update = Fader.update_useBand_linear;
			} else {
				//update = Fader.update_default_circular;
				//update = Fader.update_default_linear;
			}
		}
		*/
		
		//end of private methods
		//------------------------------------------------------------------------------------------------
		
		
		//accessors
		//------------------------------------------------------------------------------------------------
		
		public function get position():Number {
			return _position;
		}
		
		public function set position(value:Number):void {
			_position = value;
		}
		
		public function get easingL():Function {
			return _easingL;
		}
		
		public function set easingL(value:Function):void {
			_easingL = value;
		}
		
		public function get easingR():Function {
			return _easingR;
		}
		
		public function set easingR(value:Function):void {
			_easingR = value;
		}
		
		/*
		internal function get useBand():Boolean {
			return _useBand;
		}
		
		internal function set useBand(value:Boolean):void {
			_useBand = value;
			setUpdate();
		}
		*/
		
		public function get bandwidth():Number {
			return _bandwidthL + _bandwidthR;
		}
		
		public function set bandwidth(value:Number):void {
			value = CJMath.clamp(value, 0, Number.MAX_VALUE);
			_bandwidthL = _bandwidthR = value / 2;
		}
		
		public function get bandwidthL():Number {
			return _bandwidthL;
		}
		
		public function set bandwidthL(value:Number):void {
			_bandwidthL = CJMath.clamp(value, 0, Number.MAX_VALUE);
		}
		
		public function get bandwidthR():Number {
			return _bandwidthR;
		}
		
		public function set bandwidthR(value:Number):void {
			_bandwidthR = CJMath.clamp(value, 0, Number.MAX_VALUE);
		}
		
		//end of accessors
		//------------------------------------------------------------------------------------------------
	}
}